package com.dong.test;

import com.dong.dao.IDeptDao;
import com.dong.entity.Dept;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class testDept {
    private SqlSession sqlSession;
    private InputStream in;
    private IDeptDao deptDao;

    @Before
    public void init() throws IOException {
        in = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        sqlSession = factory.openSession();
        deptDao = sqlSession.getMapper(IDeptDao.class);
    }
    @After
    public void destroy() throws IOException {
        sqlSession.commit();
        sqlSession.close();
        in.close();
    }
    @Test
    public void testFindAll(){
        List<Dept> depts = deptDao.findAll(1);
        for (Dept d:depts) {
            System.out.println("每个部门的所有员工");
            System.out.println(d);
        }
    }
//    @Test
//    public void testFindById(){
//        Dept dept = deptDao.findById(2);
//        System.out.println(dept);
//    }
}
